package service

import (
	"server/global"
	"server/plugin/mall/model"
	"server/plugin/mall/model/request"
)

var A规格设置 = new(guigeshezhi)

type guigeshezhi struct{}

// CreateA规格设置 创建规格设置记录
// Author [yourname](https://github.com/yourname)
func (s *guigeshezhi) CreateA规格设置(guigeshezhi *model.A规格设置) (err error) {
	err = global.GVA_DB.Create(guigeshezhi).Error
	return err
}

// DeleteA规格设置 删除规格设置记录
// Author [yourname](https://github.com/yourname)
func (s *guigeshezhi) DeleteA规格设置(ID string) (err error) {
	err = global.GVA_DB.Delete(&model.A规格设置{}, "id = ?", ID).Error
	return err
}

// DeleteA规格设置ByIds 批量删除规格设置记录
// Author [yourname](https://github.com/yourname)
func (s *guigeshezhi) DeleteA规格设置ByIds(IDs []string) (err error) {
	err = global.GVA_DB.Delete(&[]model.A规格设置{}, "id in ?", IDs).Error
	return err
}

// UpdateA规格设置 更新规格设置记录
// Author [yourname](https://github.com/yourname)
func (s *guigeshezhi) UpdateA规格设置(guigeshezhi model.A规格设置) (err error) {
	err = global.GVA_DB.Model(&model.A规格设置{}).Where("id = ?", guigeshezhi.ID).Updates(&guigeshezhi).Error
	return err
}

// GetA规格设置 根据ID获取规格设置记录
// Author [yourname](https://github.com/yourname)
func (s *guigeshezhi) GetA规格设置(ID string) (guigeshezhi model.A规格设置, err error) {
	err = global.GVA_DB.Where("id = ?", ID).First(&guigeshezhi).Error
	return
}

// GetA规格设置InfoList 分页获取规格设置记录
// Author [yourname](https://github.com/yourname)
func (s *guigeshezhi) GetA规格设置InfoList(info request.A规格设置Search) (list []model.A规格设置, total int64, err error) {
	limit := info.PageSize
	offset := info.PageSize * (info.Page - 1)
	// 创建db
	db := global.GVA_DB.Model(&model.A规格设置{})
	var guigeshezhis []model.A规格设置
	// 如果有条件搜索 下方会自动创建搜索语句
	if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
		db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
	}
	err = db.Count(&total).Error
	if err != nil {
		return
	}

	if limit != 0 {
		db = db.Limit(limit).Offset(offset)
	}
	err = db.Find(&guigeshezhis).Error
	return guigeshezhis, total, err
}

func (s *guigeshezhi) GetA规格设置Public() {

}
